package com.dongdong.frog;

import java.io.PrintStream;
import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class MaopaoTest {


    public static void main(String[] args) {//冒泡算法

        try {   //防止控制台乱码
            System.setOut(new PrintStream(System.out, true, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            e.printStackTrace();
        }

        int[] arr={25,13,335,6,23};
        System.out.println(Arrays.toString(bubbleSort(arr)));
    }

    private static int[] bubbleSort(int[] nums) {
        int len = nums.length;

        if (len == 0||len == 1){
            return nums;
        }
        for (int i = 0; i < len; i++) {

            for (int j = 0, subLen= len-1-j;j<subLen; j++) {
                if (nums[j+1]<nums[j]) {
                    int temp=nums[j+1];
                    nums[j+1]=nums[j];
                    nums[j]=temp;
                }

            }

        }
        return nums;

        }






}
